#
# Run experiments for diploma thesis (new, DPM kernels).
#

use strict;
use warnings;

my $home = 'C:\Users\ungerma\Desktop\DA\dual-process-model\dpm';
my $dpm = 'gen\results\qq';
my $l = 'gen\results\q_';
my $r = 'gen\results\_q';

my ($n, $lbr, $rbl, $lbd, $rbd, $sbd, ) = (0, 0, 0, 0, 0, 0, );

opendir D, "$dpm" or die "Could not open dir: $!\n";
my @files = grep(/pr-\d+/i, readdir D);
foreach my $file (@files) {

  next unless $file =~ /pr-(\d+)-\d+-(\d+)-(\d+)-(\d+)/;
  my ($g, $lhs, $rhs, $prec,) = ($2, $3, $4, $1);
  my ($lprec, $rprec) = ("n.a.", "n.a.");
  opendir LEFT, $l or die "Could not open dir: $!\n";
  opendir RIGHT, $r or die "Could not open dir: $!\n";
  my @lfiles = grep(/pr-\d+-\d+-$g-$lhs-0/i, readdir LEFT);
  if(scalar @lfiles == 1) {
      $lfiles[0] =~ /pr-(\d+)/;
	  $lprec = $1;
  }
  my @rfiles = grep(/pr-\d+-\d+-$g-1-$rhs/i, readdir RIGHT);
  if(scalar @rfiles == 1) {
      $rfiles[0] =~ /pr-(\d+)/;
	  $rprec = $1;
  }
  print "***" if ($lprec ne "n.a." && $lprec > $prec) || 
                 ($rprec ne "n.a." &&$rprec > $prec);
  print "$g-$lhs-$rhs $prec $lprec $rprec\n";
  
  ++$n;
  ++$lbr if $lprec ne "n.a." && $rprec ne "n.a." && $lprec > $rprec;
  ++$rbl if $lprec ne "n.a." && $rprec ne "n.a." && $rprec > $lprec;
  ++$lbd if $lprec ne "n.a." && $prec  ne "n.a." && $lprec > $prec;
  ++$rbd if $rprec ne "n.a." && $prec  ne "n.a." && $rprec > $prec;
  ++$sbd if ($rprec ne "n.a." && $prec  ne "n.a." && $rprec > $prec) ||
            ($lprec ne "n.a." && $prec  ne "n.a." && $lprec > $prec);
  
  closedir LEFT;
  closedir RIGHT;

}
closedir D;
print "----------\n";
print "N: $n\n";
print "LHS better than RHS: $lbr\n";
print "RHS better than LHS: $rbl\n";
print "LHS better than DPM: $lbd\n";
print "RHS better than DPM: $rbd\n";
print "SPM better than DPM: $sbd\n"
